#ifndef PLATFORMTYPES_H
#define PLATFORMTYPES_H

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>

#define CPU_TYPE_8      8
#define CPU_TYPE_16     16
#define CPU_TYPE_32     32
#define CPU_TYPE_64     64

#define MSB_FIRST       0
#define LSB_FIRST       1

#define HIGH_BYTE_FIRST 0
#define LOW_BYTE_FIRST  1

/***********************这些建议定义到编译选项******************************/
#define CPU_TYPE            CPU_TYPE_32  
#define CPU_BIT_ORDER       MSB_FIRST
#define CPU_BYTE_ORDER      HIGH_BYTE_FIRST
/**************************************************************************/

typedef     uint8_t             boolean;
typedef     uint8_t             uint8;
typedef     uint16_t            uint16;
typedef     uint32_t            uint32;
typedef     uint64_t            uint64;
typedef     int8_t              sint8;
typedef     int16_t             sint16;
typedef     int32_t             sint32;
typedef     float               float32;
typedef     double              float64;

#ifndef FALSE
#define FALSE		(0U)
#endif
#ifndef TRUE
#define TRUE		(1U)
#endif

#ifndef NULL
#define NULL        0x00000000
#endif

#define U16_HIGH(u16)      ((uint8) (((u16) >> 8) & 0x00ff))
#define U16_LOW(u16)       ((uint8) ( (u16)       & 0x00ff))
/** Big-Endian and Little-Endian */
#define U16_TO_U8_BE(u16)    U16_HIGH(u16), U16_LOW(u16)
#define U16_TO_U8_LE(u16)    U16_LOW(u16), U16_HIGH(u16)

#define U32_BYTE3(u32)     ((uint8) ((((uint32) u32) >> 24) & 0x000000ff)) // MSB
#define U32_BYTE2(u32)     ((uint8) ((((uint32) u32) >> 16) & 0x000000ff))
#define U32_BYTE1(u32)     ((uint8) ((((uint32) u32) >> 8)  & 0x000000ff))
#define U32_BYTE0(u32)     ((uint8) (((uint32) u32)         & 0x000000ff)) // LSB

/** Big-Endian and Little-Endian */
#define U32_TO_U8_BE(u32)    U32_BYTE3(u32), U32_BYTE2(u32), U32_BYTE1(u32), U32_BYTE0(u32)
#define U32_TO_U8_LE(u32)    U32_BYTE0(u32), U32_BYTE1(u32), U32_BYTE2(u32), U32_BYTE3(u32)

#if (CPU_TYPE == CPU_TYPE_32)
#define ARC_MEM_ALIGN __attribute__ ((aligned(4)))
#elif (CPU_TYPE == CPU_TYPE_8)
#define ARC_MEM_ALIGN __attribute__ ((aligned(1)))
#endif

#endif
